using System;
using System.Collections.Generic;

using MonPocGarage.ArmyContracts.Common;
using MonPocGarage.ArmyContracts.Common.Enums;

namespace MonPocGarage.ArmyContracts
{
    public class Unit : ICloneable
    {
        public string UnitName { get; set; }

        public string DisplayName { get { return UnitName + " (" + UnitType + ")"; } }

        public string UnitID
        {
            get { return UnitName.Replace(" ", string.Empty) + "_" + UnitType; }
        }

        public Guid InstanceKey { get; private set; }

        public string ImagePath { get { return BuildImagePath(); } }

        public UnitType UnitType { get; set; }

        public int UnitCost { get; set; }

        public Faction Faction { get; set; }

        public Agenda Agenda { get; set; }

        public StatBlock Stats { get; set; }

        public List<IAbility> Abilities { get; set; }

        public EnergyType EnergyType { get; set; }

        public Unit()
        {
            InstanceKey = Guid.NewGuid();
        }

        private Unit(Unit another)
        {
            UnitName = another.UnitName;
            InstanceKey = Guid.NewGuid();
            UnitType = another.UnitType;
            UnitCost = another.UnitCost;
            Faction = another.Faction;
            Agenda = another.Agenda;
            Stats = another.Stats;
            Abilities = another.Abilities;
            EnergyType = another.EnergyType;
        }

        private string BuildImagePath()
        {
            if (!string.IsNullOrWhiteSpace(UnitName))
            {
                string imagePath = string.Format("{0}/Images/Units/{1}/{2}_{3}.png",
                                             Environment.CurrentDirectory,
                                             Faction,
                                             UnitName.Replace(" ", "_").ToLower(),
                                             UnitType.ToString().ToLower());
                return imagePath;
            }
            return string.Empty;
        }

        public object Clone()
        {
            return new Unit(this);
        }
    }
}